$(function () {



    $.ajax({
        type: "get",
        url: "http://193.112.55.79:9090/api/getbaicaijiatitle",
        dataType: "json",
        success: function (res) {
            console.log(res.result.length);
            var html = template('goodsTitle', res);
            $('#nav_goodsTitle').html(html);
            let width = 0;
            $.each($('#nav_goodsTitle li'), function (i, e) { 
                width += $(e).innerWidth();
            });
            console.log(width);
            $('#nav_goodsTitle').css({
                'width': `${width}px`
            })

            let leftscroll = new IScroll('.nav_titleList', {
                scrollX: true
            });

        }
    });
    // 封装渲染商品列表函数
    function goods_listHtml(index) {

        $.ajax({
            type: "get",
            url: "http://193.112.55.79:9090/api/getbaicaijiaproduct",
            data: {
                titleid: index
            },
            dataType: "json",
            success: function (res) {
                console.log(res);
                var html = template('goodsList', res);
                $('#allgoodsList').html(html);
            }
        });
    }

    goods_listHtml(0);

    $('#nav_goodsTitle').on('click', 'li', function (e) {

        $(this).css({
            "border-bottom": "2px solid #e4393c"
        }).children().css({
            "color": "#e4393c"
        });

        $(this).siblings().css({
            "border-bottom": "none"
        }).children().css({
            "color": "#000"
        });

        let index = $(this).data('index');
        console.log(index);
        goods_listHtml(index);


    });



});